package com.neutech.Demo1;

import com.mysql.cj.xdevapi.Collection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo2 {
    public static void main(String[] args) {
//        1.加载驱动类
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            //2.获取连接
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");

            //3.修改表中的数据
            Statement statement = connection.createStatement();

//          String sql ="insert into users values('张三','888888','zhangsan@126.com','1986-10-11',1200), "
//                  +"('李四','999999','lisi@126.com','1988-10-23',700),"+"('王五','777777','wangwu@126.com','1990-9-11',2150)";
//
//            System.out.println(statement.executeUpdate(sql));

//            String sql2 ="update users set birthday = NOW() where name='张三'";
//            System.out.println(statement.executeUpdate(sql2));


            String sql3 ="select * from users where birthday > '1987-12-31'";
            ResultSet resultSet = statement.executeQuery(sql3);

            while (resultSet.next()){
                System.out.print(resultSet.getString("name"));
                System.out.print(resultSet.getString("pwd"));
                System.out.print(resultSet.getString("email"));
                System.out.print(resultSet.getString("birthday"));
                System.out.println(resultSet.getInt("money"));
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }




    }

    }

